define(['./../../initial'],
    function() {
        var app = angular.module('App.home');        
        app.controller('notice.review.detailCtrl', ['$timeout', '$scope', '$rootScope', '$state', '$stateParams', 'curReview', 'Project', 'showMsg', 'chartFactory', 'showInfoModal', 'reviewProjectList', function($timeout, $scope, $rootScope, $state, $stateParams, curReview, Project, showMsg, chartFactory, showInfoModal, reviewProjectList) {
            // $timeout(function() {
            //     $('.ui.top.attached.tabular.menu .item')
            //         .tab();
            // }, 400);
            $scope.curReview = curReview;
            var prj = angular.extend(new Project(), curReview);

            $scope.curStatus = null;
            //获取工况列表
            curReview && prj
                .getStatusList()
                .then(function(statusList) {
                    if (statusList && statusList.length > 0) {
                        $scope.curStatus = statusList[statusList.length - 1];
                    }
                });
            //获取审核的测项的变化量
            curReview && prj.items.forEach(function(item, index) {
                prj.getReviewChange(item.monitorType, item.location, curReview.date)
                    .then((function(dex) {
                        return function(data) {
                            curReview.items[dex].changes = data;
                            chartFactory.createPointsChartByLocationSummary('#chart' + dex, data);
                        };
                    })(index));
            });

            $scope.handleProject = function(action) {
                if (action === 1) {
                    showInfoModal({
                        title: '确认通过审核',
                        content: '数据一旦提交就会在前端界面显示,确认通过审核吗?',
                        button: 2,
                        onConfirm: function() {
                            prj.postReviewProject({
                                date: curReview.date,
                                prjId: curReview.prjId,
                                action: 1
                            }).then(function() {
                                curReview.handled = true;
                                curReview.pass = true;
                                $timeout(function() {
                                    showMsg('审核成功', 'info');
                                    $timeout(function() {
                                        reviewProjectList.splice($stateParams.uid, 1);
                                        $state.go('notice.review');
                                    }, 2000);
                                }, 1000);
                            });
                        }
                    });
                } else {
                    showInfoModal({
                        title: '确认拒绝审核',
                        content: '一旦拒绝,会删除当天该项目所有待审核的数据,且不可恢复,是否拒绝审核?',
                        button: 2,
                        onConfirm: function() {
                            prj.postReviewProject({
                                date: curReview.date,
                                prjId: curReview.prjId,
                                action: 0
                            }).then(function() {
                                curReview.handled = true;
                                curReview.pass = false;
                                $timeout(function() {
                                    showMsg('拒绝审核成功', 'info');
                                    $timeout(function() {
                                        reviewProjectList.splice($stateParams.uid, 1);
                                        $state.go('notice.review');
                                    }, 2000);
                                }, 1000);
                            });
                        }
                    });
                }
            };

        }]);
    });
